﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Threading;
using System.Text.RegularExpressions;

namespace ITQUIZ
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public int numberOfEasyQuestions = File.ReadLines(@"../../EasyQuestions/EasyQuestions.txt").Count();
        public int numberOfMediumQuestions = File.ReadLines(@"../../MediumQuestions/MediumQuestions.txt").Count();
        public int numberOfHardQuestions = File.ReadLines(@"../../HardQuestions/HardQuestions.txt").Count();
        public HashSet<int> showedEasyQuestions = new HashSet<int>();
        public HashSet<int> showedMediumQuestions = new HashSet<int>();
        public HashSet<int> showedHardQuestions = new HashSet<int>();
        
        public MainWindow()
        {
            InitializeComponent();

        }


        private void Grid_Initialized(object sender, EventArgs e)
        {
            //EasyQuestionsButton.Tag = 0;
        }


        private void OnShowFirstQuestionClick(object sender, EventArgs e)
        {

            Random randomQuestion = new Random();
            int questionNumber = randomQuestion.Next(0, numberOfEasyQuestions);
            while (showedEasyQuestions.Contains(questionNumber) && showedEasyQuestions.Count != numberOfEasyQuestions)
            {
                questionNumber = randomQuestion.Next(0, numberOfEasyQuestions);
            }

            if (numberOfEasyQuestions == showedEasyQuestions.Count)
            {
                EasyQuestionsButton.IsEnabled = false;
            }
            else
            {
                var easyQuestion = new EasyQuestion();
                easyQuestion.questionNum = questionNumber;
                
                showedEasyQuestions.Add(questionNumber);
                var questWindow = new EasyQuestionWindow();
                string questionText = easyQuestion.GetQuestion();
                var text = questionText.Split('^');

                questionText = string.Join(Environment.NewLine, text);
                questWindow.QuestionText.Text = questionText;
                questWindow.AnswerOne.Content = easyQuestion.GetQuestionAnswer(0);
                questWindow.AnswerTwo.Content = easyQuestion.GetQuestionAnswer(1);
                questWindow.AnswerThree.Content = easyQuestion.GetQuestionAnswer(2);
                questWindow.AnswerFour.Content = easyQuestion.GetQuestionAnswer(3);
                questWindow.QuestionText.Tag = easyQuestion.GetCorrectAnswer(); // Terrible workaround...if you have time implement data-binding
                questWindow.Show();
                
            }
            
        }


         private void OnShowMediumQuestionsClick(object sender, EventArgs e)
        {
            Random randomQuestion = new Random();
            int questionNumber = randomQuestion.Next(0, numberOfMediumQuestions);
            while (showedMediumQuestions.Contains(questionNumber) && showedMediumQuestions.Count != numberOfMediumQuestions)
            {
                questionNumber = randomQuestion.Next(0, numberOfMediumQuestions);
            }

            if (numberOfMediumQuestions == showedMediumQuestions.Count)
            {
                MediumQuestionsButton.IsEnabled = false;
            }
            else
            {
                var MediumQuestion = new MediumQuestion();
                MediumQuestion.questionNum = questionNumber;
                
                showedMediumQuestions.Add(questionNumber); 
                var questWindow = new MediumQuestionWindow();
                string questionText = MediumQuestion.GetQuestion();
                var text = questionText.Split('^');
                questionText = string.Join(Environment.NewLine, text);
                questWindow.QuestionText.Text = questionText;
                questWindow.AnswerOne.Content = MediumQuestion.GetQuestionAnswer(0);
                questWindow.AnswerTwo.Content = MediumQuestion.GetQuestionAnswer(1);
                questWindow.AnswerThree.Content = MediumQuestion.GetQuestionAnswer(2);
                questWindow.AnswerFour.Content = MediumQuestion.GetQuestionAnswer(3);
                questWindow.QuestionText.Tag = MediumQuestion.GetCorrectAnswer();// Terrible workaround...if you have time implement data-binding
                questWindow.Show();
            }
            
            
        }



         private void OnShowHardQuestionsClick(object sender, EventArgs e)
         {
             Random randomQuestion = new Random();
             int questionNumber = randomQuestion.Next(0, numberOfHardQuestions);
             while (showedHardQuestions.Contains(questionNumber) && showedHardQuestions.Count != numberOfHardQuestions)
             {
                 questionNumber = randomQuestion.Next(0, numberOfHardQuestions);
             }

             if (numberOfHardQuestions == showedHardQuestions.Count)
             {
                 HardQuestionsButton.IsEnabled = false;
             }
             else
             {
                 var HardQuestion = new HardQuestion();
                 HardQuestion.questionNum = questionNumber;

                 showedHardQuestions.Add(questionNumber);
                 var questWindow = new HardQuestionWindow();
                 string questionText = HardQuestion.GetQuestion();
                 var text = questionText.Split('^');
                 questionText = string.Join(Environment.NewLine, text);
                 questWindow.QuestionText.Text = questionText;
                 questWindow.AnswerOne.Content = HardQuestion.GetQuestionAnswer(0);
                 questWindow.AnswerTwo.Content = HardQuestion.GetQuestionAnswer(1);
                 questWindow.AnswerThree.Content = HardQuestion.GetQuestionAnswer(2);
                 questWindow.AnswerFour.Content = HardQuestion.GetQuestionAnswer(3);
                 questWindow.QuestionText.Tag = HardQuestion.GetCorrectAnswer();// Terrible workaround...if you have time implement data-binding
                 questWindow.Show();
             }


         }

    }
}
